<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">

		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../css/mui.min.css">
	</head>

	<body>
		<!--下拉刷新容器-->
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!--数据列表-->
				<ul class="mui-table-view mui-table-view-chevron">

				</ul>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script>
			 //通过mui.init方法中pullRefresh参数 配置下拉刷新的各项参数
			mui.init({
				pullRefresh: {
					//下拉刷新的容器标识
					container: '#pullrefresh',
					//下拉刷新
					down: {
						contentdown: "下拉刷新",
						contentover: "松开立即刷新",
						contentrefresh: "正在刷新数据...",
						//刷新函数
						callback: pulldownRefresh
					},
					//上拉加载更多
					up: {
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});
			 //下拉刷新 具体业务实现
			function pulldownRefresh() {
				setTimeout(function() {
					var table = document.body.querySelector('.mui-table-view');
					var cells = document.body.querySelectorAll('.mui-table-view-cell');
					for (var i = cells.length, len = i + 3; i < len; i++) {
						var li = document.createElement('li');
						//设置li的id属性
						li.id = i+1;
						li.className = 'mui-table-view-cell';
						li.innerHTML = '<a class="mui-navigate-right">Item ' + (i + 1) + ' new</a>';
						//下拉刷新，新纪录插到最前面；
						table.insertBefore(li, table.firstChild);
					}
					//注意：加载完数据后，必须执行此代码，若为ajax请求，则需将如下代码放置在处理ajax响应数据之后
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
				}, 1500);
			}
			
			//上拉加载更多 具体业务实现
			var count = 0;
			function pullupRefresh() {
				setTimeout(function() {
					mui('#pullrefresh').pullRefresh().endPullupToRefresh((++count > 2)); //参数为true代表没有更多数据了。
					var table = document.body.querySelector('.mui-table-view');
					var cells = document.body.querySelectorAll('.mui-table-view-cell');
					for (var i = cells.length, len = i + 20; i < len; i++) {
						var li = document.createElement('li');
						//设置li的id属性
						li.id = i+1;
						li.className = 'mui-table-view-cell';
						li.innerHTML = '<a class="mui-navigate-right">Item ' + (i + 1) + '</a>';
						table.appendChild(li);
					}
				}, 1500);
			}
			//列表 绑定tap事件
			mui(".mui-table-view").on('tap','.mui-table-view-cell',function(){
				var id = this.getAttribute("id");
				var showinfo = "you click item "+id;
				console.log(showinfo);
				plus.nativeUI.alert(showinfo);
			})
			
			
			if (mui.os.plus) {
				mui.plusReady(function() {
					setTimeout(function() {
						mui('#pullrefresh').pullRefresh().pullupLoading();
					}, 1000);
				});
			} else {
				mui.ready(function() {
					mui('#pullrefresh').pullRefresh().pullupLoading();
				});
			}
		</script>
	</body>

</html>